package com.example.gulimall.ware.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.example.common.constant.WareConstant;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.PageUtils;
import com.example.common.utils.Query;

import com.example.gulimall.ware.dao.WareOrderTaskDetailDao;
import com.example.common.entity.ware.WareOrderTaskDetailEntity;
import com.example.gulimall.ware.service.WareOrderTaskDetailService;


@Service("wareOrderTaskDetailService")
public class WareOrderTaskDetailServiceImpl extends ServiceImpl<WareOrderTaskDetailDao, WareOrderTaskDetailEntity> implements WareOrderTaskDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WareOrderTaskDetailEntity> page = this.page(
                new Query<WareOrderTaskDetailEntity>().getPage(params),
                new QueryWrapper<WareOrderTaskDetailEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<WareOrderTaskDetailEntity> selectTaskDetailsWithOrderSn(String orderSn) {

        if (StrUtil.isBlank(orderSn)) {
            return Collections.emptyList();
        }

        List<WareOrderTaskDetailEntity> details = this.baseMapper
                .selectTaskDetailsWithOrderSn(orderSn, WareConstant.StockStatus.LOCKED.getCode());

        if (CollectionUtil.isEmpty(details)) {
            return Collections.emptyList();
        }

        return details;
    }

}